package com.itboye.ihomebank.presenter;

import java.util.Observer;

import com.itboye.ihomebank.base.BasePresenter;
import com.itboye.ihomebank.base.ICompleteListener;
import com.itboye.ihomebank.bean.PersonDataBean;
import com.itboye.ihomebank.bean.ResultEntity;
import com.itboye.ihomebank.interfaces.IUserInterface;
import com.itboye.ihomebank.responsitory.UserRepository;

/***
 * 
 * @author 递增给Responsitory
 * 
 */
public class UserPresenter extends BasePresenter implements
		IUserInterface<PersonDataBean> {

	public UserPresenter(Observer observer) {
		super(observer);
	}

	// 用户登录
	public static final String user_success = UserPresenter.class.getName()
			+ "_User_success";// 由此判断请求的接口
	public static final String user_fail = UserPresenter.class.getName()
			+ "_User_fail";

	// 发送验证码
	public static final String send_success = UserPresenter.class.getName()
			+ "_Send_success";// 由此判断请求的接口
	public static final String send_fail = UserPresenter.class.getName()
			+ "_Send_fail";

	// 验证验证码
	public static final String verification_success = UserPresenter.class
			.getName() + "_Verification_success";// 由此判断请求的接口
	public static final String verification_fail = UserPresenter.class
			.getName() + "_Verification_fail";
	// 注册
	public static final String register_success = UserPresenter.class.getName()
			+ "_Rregister_success";// 由此判断请求的接口
	public static final String register_fail = UserPresenter.class.getName()
			+ "_Register_fail";

	// 手机找回密码
	public static final String backPass_success = UserPresenter.class.getName()
			+ "_BackPass_success";// 由此判断请求的接口
	public static final String backPass_fail = UserPresenter.class.getName()
			+ "_BackPass_fail";
	// 修改性别
	public static final String updateSex_success = UserPresenter.class
			.getName() + "_UpdateSex_success";// 由此判断请求的接口
	public static final String updateSex_fail = UserPresenter.class.getName()
			+ "_UpdateSex_fail";
	// 修改昵称
	public static final String updateNickname_success = UserPresenter.class
			.getName() + "_UpdateNickname_success";// 由此判断请求的接口
	public static final String updateNickname_fail = UserPresenter.class
			.getName() + "_UpdateNickname_fail";
	// 修改昵称
	public static final String updateHead_success = UserPresenter.class
			.getName() + "_UpdateHead_success";// 由此判断请求的接口
	public static final String updateHead_fail = UserPresenter.class.getName()
			+ "_UpdateHead_fail";
	// 绑定手机换绑定
	public static final String updateorbindphone_success = UserPresenter.class
			.getName() + "_Updateorbindphone_success";// 由此判断请求的接口
	public static final String updateorbindphone_fail = UserPresenter.class
			.getName() + "_Updateorbindphone_fail";

	// 更改密码
	public static final String updatepwdbypwd_success = UserPresenter.class
			.getName() + "_Updatepwdbypwd_success";// 由此判断请求的接口
	public static final String updatepwdbypwd_fail = UserPresenter.class
			.getName() + "_Updatepwdbypwd_fail";
	// 手机找密
	public static final String updatepwdbyphone_success = UserPresenter.class
			.getName() + "_Updateorbindphone_success";// 由此判断请求的接口
	public static final String updatepwdbyphone_fail = UserPresenter.class
			.getName() + "_Updateorbindphone_fail";
	// 获取系统消息
	public static final String systemmessage_success = UserPresenter.class
			.getName() + "_Updateorbindphone_success";// 由此判断请求的接口
	public static final String systemmessage_fail = UserPresenter.class
			.getName() + "_Updateorbindphone_fail";

	// 获取方向
	public static final String getOritation_success = UserPresenter.class
			.getName() + "_GetOritation_success";// 由此判断请求的接口
	public static final String getOritation_fail = UserPresenter.class
			.getName() + "_GetOritation_fail";

	// 房源发布
	public static final String houseAdd_success = UserPresenter.class.getName()
			+ "_HouseAdd_success";// 由此判断请求的接口
	public static final String houseAdd_fail = UserPresenter.class.getName()
			+ "_HouseAdd_fail";

	// 实名认证
	public static final String realName_success = UserPresenter.class.getName()
			+ "_RealName_success";// 由此判断请求的接口
	public static final String realName_fail = UserPresenter.class.getName()
			+ "_RealName_fail";

	// 消息分页查询
	public static final String sysMess_success = UserPresenter.class.getName()
			+ "_SysMess_success";// 由此判断请求的接口
	public static final String sysMess_fail = UserPresenter.class.getName()
			+ "_SysMess_fail";

	// 修改钥匙信息
	public static final String updateKey_success = UserPresenter.class
			.getName() + "_UpdateKey_success";// 由此判断请求的接口
	public static final String updateKey_fail = UserPresenter.class.getName()
			+ "_UpdateKey_fail";

	// 查询钥匙
	public static final String myKey_success = UserPresenter.class.getName()
			+ "_MyKey_success";// 由此判断请求的接口
	public static final String myKey_fail = UserPresenter.class.getName()
			+ "_MyKey_fail";
	// 绑定科技侠
	public static final String bindKeJiXia_success = "_BindKeJiXia_success";
	public static final String bindKeJiXia_fail = "_BindKeJiXia_fail";

	// 获取合同参数
	public static final String heTongParams_success = "_HeTongParams_success";
	public static final String heTongParams_fail = "_HeTongParams_fail";

	// 提交合同
	public static final String heTongTiJiao_success = "_HeTongTiJiao_success";
	public static final String heTongTiJiao_fail = "_HeTongTiJiao_fail";

	// 确认合同
	public static final String queRenHeTong_success = "_QueRenHeTong_success";
	public static final String queRenHeTong_fail = "_QueRenHeTong_fail";
	// 签约详情
	public static final String qianyuedetail_success = "_Qianyuedetail_success";
	public static final String qianyuedetail_fail = "_Qianyuedetail_fail";
	// 房源收藏列表
	public static final String myCollection_success = "_MyCollection_success";
	public static final String myCollection_fail = "_MyCollection_fail";

	@Override
	public void login(String userName, String pwd) {
		IUserInterface<PersonDataBean> user = new UserRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(user_success);
						UserPresenter.this.setChanged();
						UserPresenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						result.setEventTag(Tag_Error);
						result.setEventType(user_fail);
						UserPresenter.this.setChanged();
						UserPresenter.this.notifyObservers(result);

					}
				});
		user.login(userName, pwd);
	}

	/**
	 * 发送短信
	 */
	@Override
	public void send(String phone, String code) {
		IUserInterface<PersonDataBean> user = new UserRepository(
				new ICompleteListener() {
					@Override
					public void success(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(send_success);
						UserPresenter.this.setChanged();
						UserPresenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						// TODO Auto-generated method stub
						result.setEventTag(Tag_Error);
						result.setEventType(send_fail);
						UserPresenter.this.setChanged();
						UserPresenter.this.notifyObservers(result);

					}
				});
		user.send(phone, code);
	}

	/**
	 * 验证验证码
	 */
	@Override
	public void verification(String mobile, String code_type, String code) {
		IUserInterface<PersonDataBean> user = new UserRepository(
				new ICompleteListener() {
					@Override
					public void success(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(verification_success);
						UserPresenter.this.setChanged();
						UserPresenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						// TODO Auto-generated method stub
						result.setEventTag(Tag_Error);
						result.setEventType(verification_fail);
						UserPresenter.this.setChanged();
						UserPresenter.this.notifyObservers(result);

					}
				});
		user.verification(mobile, code_type, code);

	}

	/**
	 * 注册
	 */
	@Override
	public void register(String reg_type, String from, String code,
			String username, String password) {
		IUserInterface<PersonDataBean> user = new UserRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(register_success);
						UserPresenter.this.setChanged();
						UserPresenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						result.setEventTag(Tag_Error);
						result.setEventType(register_fail);
						UserPresenter.this.setChanged();
						UserPresenter.this.notifyObservers(result);

					}
				});
		user.register(reg_type, from, code, username, password);

	}

	/**
	 * 手机找回密码
	 */
	@Override
	public void backPass(String mobile, String code, String psw) {
		IUserInterface<PersonDataBean> user = new UserRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(backPass_success);
						UserPresenter.this.setChanged();
						UserPresenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(backPass_fail);
						UserPresenter.this.setChanged();
						UserPresenter.this.notifyObservers(result);

					}
				});
		user.backPass(mobile, code, psw);

	}

	/**
	 * 修改性别
	 */
	@Override
	public void updateSex(String uid, String sex) {
		IUserInterface<PersonDataBean> user = new UserRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(updateSex_success);
						UserPresenter.this.setChanged();
						UserPresenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(updateSex_fail);
						UserPresenter.this.setChanged();
						UserPresenter.this.notifyObservers(result);

					}
				});
		user.updateSex(uid, sex);

	}

	/**
	 * 修改昵称
	 */
	@Override
	public void updateNickname(String uid, String nickname) {
		IUserInterface<PersonDataBean> user = new UserRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(updateNickname_success);
						UserPresenter.this.setChanged();
						UserPresenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(updateNickname_fail);
						UserPresenter.this.setChanged();
						UserPresenter.this.notifyObservers(result);

					}
				});
		user.updateNickname(uid, nickname);

	}

	/**
	 * 修改头像
	 */
	@Override
	public void updateHead(String uid, String type, String image) {
		IUserInterface<PersonDataBean> user = new UserRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(updateHead_success);
						UserPresenter.this.setChanged();
						UserPresenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(updateHead_fail);
						UserPresenter.this.setChanged();
						UserPresenter.this.notifyObservers(result);

					}
				});
		user.updateHead(uid, type, image);

	}

	@Override
	public void getConfig() {
		// TODO Auto-generated method stub
		IUserInterface<PersonDataBean> user = new UserRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(updateHead_success);
						UserPresenter.this.setChanged();
						UserPresenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						result.setEventTag(Tag_Error);
						result.setEventType(updateHead_fail);
						UserPresenter.this.setChanged();
						UserPresenter.this.notifyObservers(result);

					}
				});
		user.getConfig();
	}

	@Override
	public void bindPhone(String uid, String phone, String code,
			String password, boolean isChange) {
		// TODO Auto-generated method stub
		IUserInterface<PersonDataBean> user = new UserRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(updateorbindphone_success);
						UserPresenter.this.setChanged();
						UserPresenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						result.setEventTag(Tag_Error);
						result.setEventType(updateorbindphone_fail);
						UserPresenter.this.setChanged();
						UserPresenter.this.notifyObservers(result);

					}
				});
		user.bindPhone(uid, phone, code, password, isChange);
	}

	@Override
	public void updatePwdByPwd(String uid, String oldPassword,
			String newPassword) {
		// TODO Auto-generated method stub
		IUserInterface<PersonDataBean> user = new UserRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(updatepwdbypwd_success);
						UserPresenter.this.setChanged();
						UserPresenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(updatepwdbypwd_fail);
						UserPresenter.this.setChanged();
						UserPresenter.this.notifyObservers(result);

					}
				});
		user.updatePwdByPwd(uid, oldPassword, newPassword);
	}

	@Override
	public void updatePwdByPhone(String uid, String mobile, String code,
			String newPassword) {
		// TODO Auto-generated method stub
		IUserInterface<PersonDataBean> user = new UserRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(updatepwdbyphone_success);
						UserPresenter.this.setChanged();
						UserPresenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						result.setEventTag(Tag_Error);
						result.setEventType(updatepwdbyphone_fail);
						UserPresenter.this.setChanged();
						UserPresenter.this.notifyObservers(result);

					}
				});
		user.updatePwdByPhone(uid, mobile, code, newPassword);
	}

	@Override
	public void systemMessage(String uid, String msgType) {
		// TODO Auto-generated method stub
		IUserInterface<PersonDataBean> user = new UserRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(systemmessage_success);
						UserPresenter.this.setChanged();
						UserPresenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						result.setEventTag(Tag_Error);
						result.setEventType(systemmessage_fail);
						UserPresenter.this.setChanged();
						UserPresenter.this.notifyObservers(result);

					}
				});
		user.systemMessage(uid, msgType);
	}

	@Override
	public void getDirection() {
		// TODO Auto-generated method stub
		IUserInterface<PersonDataBean> user = new UserRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(getOritation_success);
						UserPresenter.this.setChanged();
						UserPresenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						result.setEventTag(Tag_Error);
						result.setEventType(getOritation_fail);
						UserPresenter.this.setChanged();
						UserPresenter.this.notifyObservers(result);

					}
				});
		user.getDirection();
	}

	/**
	 * 房源发布
	 */
	public void getHouseAdd(String uid, String imgs, String community_code,
			int rent_type, String contact_name, String contact_phone,
			String rent, String size, String unit, String house_floor,
			String floors, String house_decoration, String house_pay,
			String house_dir, String address, String entrust_money,
			String house_feature, String house_device, String addressdetail) {
		IUserInterface<PersonDataBean> user = new UserRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(houseAdd_success);
						UserPresenter.this.setChanged();
						UserPresenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						result.setEventTag(Tag_Error);
						result.setEventType(houseAdd_fail);
						UserPresenter.this.setChanged();
						UserPresenter.this.notifyObservers(result);

					}
				});
		user.getHouseAdd(uid, imgs, community_code, rent_type, contact_name,
				contact_phone, rent, size, unit, house_floor, floors,
				house_decoration, house_pay, house_dir, address, entrust_money,
				house_feature, house_device, addressdetail);

	}

	/**
	 * 实名认证
	 */
	public void getRealName(String uid, String realname, String idnumber,
			String code) {
		IUserInterface<PersonDataBean> user = new UserRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(realName_success);
						UserPresenter.this.setChanged();
						UserPresenter.this.notifyObservers(result);

					}

					@Override
					public void failure(ResultEntity result) {
						result.setEventTag(Tag_Error);
						result.setEventType(realName_fail);
						UserPresenter.this.setChanged();
						UserPresenter.this.notifyObservers(result);

					}
				});
		user.getRealName(uid, realname, idnumber, code);
	}

	/**
	 * 消息分页查询
	 */
	@Override
	public void getSystemMess(String uid, String msg_type, String page_no,
			String page_size) {
		IUserInterface<PersonDataBean> user = new UserRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(sysMess_success);
						UserPresenter.this.setChanged();
						UserPresenter.this.notifyObservers(result);

					}

					@Override
					public void failure(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(sysMess_fail);
						UserPresenter.this.setChanged();
						UserPresenter.this.notifyObservers(result);

					}
				});
		user.getSystemMess(uid, msg_type, page_no, page_size);
	}

	@Override
	public void bindKeJiXia(String uid, boolean isBind) {
		// TODO Auto-generated method stub
		IUserInterface<PersonDataBean> user = new UserRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(bindKeJiXia_success);
						UserPresenter.this.setChanged();
						UserPresenter.this.notifyObservers(result);

					}

					@Override
					public void failure(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(bindKeJiXia_fail);
						UserPresenter.this.setChanged();
						UserPresenter.this.notifyObservers(result);

					}
				});
		user.bindKeJiXia(uid, isBind);
	}

	@Override
	public void myKey(String uid) {
		// TODO Auto-generated method stub
		IUserInterface<PersonDataBean> user = new UserRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(myKey_success);
						UserPresenter.this.setChanged();
						UserPresenter.this.notifyObservers(result);

					}

					@Override
					public void failure(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(myKey_fail);
						UserPresenter.this.setChanged();
						UserPresenter.this.notifyObservers(result);

					}
				});
		user.myKey(uid);
	}

	@Override
	public void updateKey(String uid, String lockId, String alias) {
		// TODO Auto-generated method stub
		IUserInterface<PersonDataBean> user = new UserRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(updateKey_success);
						UserPresenter.this.setChanged();
						UserPresenter.this.notifyObservers(result);

					}

					@Override
					public void failure(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(updateKey_fail);
						UserPresenter.this.setChanged();
						UserPresenter.this.notifyObservers(result);

					}
				});
		user.updateKey(uid, lockId, alias);
	}

	@Override
	public void heTongParams(String subject) {
		// TODO Auto-generated method stub
		IUserInterface<PersonDataBean> user = new UserRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(heTongParams_success);
						UserPresenter.this.setChanged();
						UserPresenter.this.notifyObservers(result);

					}

					@Override
					public void failure(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(heTongParams_fail);
						UserPresenter.this.setChanged();
						UserPresenter.this.notifyObservers(result);

					}
				});
		user.heTongParams(subject);
	}

	@Override
	public void tiJiaoHeTong(String uid, String contractNo, String params) {
		// TODO Auto-generated method stub
		IUserInterface<PersonDataBean> user = new UserRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(heTongTiJiao_success);
						UserPresenter.this.setChanged();
						UserPresenter.this.notifyObservers(result);

					}

					@Override
					public void failure(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(heTongTiJiao_fail);
						UserPresenter.this.setChanged();
						UserPresenter.this.notifyObservers(result);

					}
				});
		user.tiJiaoHeTong(uid, contractNo, params);
	}

	@Override
	public void wanChengHeTong(String uid, String contractNo) {
		// TODO Auto-generated method stub

		IUserInterface<PersonDataBean> user = new UserRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(queRenHeTong_success);
						UserPresenter.this.setChanged();
						UserPresenter.this.notifyObservers(result);

					}

					@Override
					public void failure(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(queRenHeTong_fail);
						UserPresenter.this.setChanged();
						UserPresenter.this.notifyObservers(result);

					}
				});
		user.wanChengHeTong(uid, contractNo);
	}

	@Override
	public void qianyueDetail(String uid, String contractNo) {
		// TODO Auto-generated method stub

		IUserInterface<PersonDataBean> user = new UserRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(qianyuedetail_success);
						UserPresenter.this.setChanged();
						UserPresenter.this.notifyObservers(result);

					}

					@Override
					public void failure(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(qianyuedetail_fail);
						UserPresenter.this.setChanged();
						UserPresenter.this.notifyObservers(result);

					}
				});
		user.qianyueDetail(uid, contractNo);
	}

	@Override
	public void myCollection(String uid, String status) {
		// TODO Auto-generated method stub
		
		IUserInterface<PersonDataBean> user = new UserRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(myCollection_success);
						UserPresenter.this.setChanged();
						UserPresenter.this.notifyObservers(result);

					}

					@Override
					public void failure(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(myCollection_fail);
						UserPresenter.this.setChanged();
						UserPresenter.this.notifyObservers(result);

					}
				});
		user.myCollection(uid, status);
	}

	@Override
	public void getYWContactName(String uid, String startDate, String endDate) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void siLiao(String uid, String toUid, String msg) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void getSiXinHistory(String uid, String toUid, String begin,
			String end, String count, String next) {
		// TODO Auto-generated method stub
		
	}

}
